#include "StdAfx.h"
#include "Matrix4.h"


CMatrix4::CMatrix4(void)
{
}


CMatrix4::~CMatrix4(void)
{
}

CMatrix4 CMatrix4::operator*(const CMatrix4& rhs) const
{
	CMatrix4 matReturn;
	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 4; ++j)
		{
			for (int k = 0; k < 4; ++k)
			{
				matReturn[i][j] += (*this)[i][k] * rhs[k][j];
			}
		}
	}
	return matReturn;
}

CMatrix4& CMatrix4::operator=(const CMatrix4& rhs)
{
	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 4; ++j)
		{
			(*this)[i][j] = rhs[i][j];
		}
	}
	return *this;
}

CVector4 operator*(const CMatrix4& lhs, const CVector4& rhs)
{
	CVector4 vRet;
	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 4; ++j)
		{
			vRet[i] += lhs[i][j] * rhs[j];
		}
	}
	return vRet;
}

CMatrix4 CMatrix4::IdentityMatrix()
{
	CMatrix4 ret;

	for (int i = 0; i < 4; ++i)
	{
		ret[i][i] = 1.f;
	}
	return ret;
}

CMatrix4 CMatrix4::TranslationMatrix(DATA_TYPE xTrans, DATA_TYPE yTrans, DATA_TYPE zTrans)
{
	CMatrix4 ret = CMatrix4::IdentityMatrix();
	ret[0][3] = xTrans;
	ret[1][3] = yTrans;
	ret[2][3] = zTrans;
	return ret;
}

CMatrix4 CMatrix4::ScalingMatrix(DATA_TYPE xScale, DATA_TYPE yScale, DATA_TYPE zScale)
{
	CMatrix4 ret;
	ret[0][0] = xScale;
	ret[1][1] = yScale;
	ret[2][2] = zScale;
	ret[3][3] = 1.f;
	return ret;
}